<?php
require_once("taskpointView.php");
require_once(CORE_DIR.'taskpointModel.php');
require_once(CORE_DIR.'pointtypeModel.php');
require_once(CORE_DIR.'taskModel.php');

class addAction extends authAction{

	function __construct(){
		$this->view = new taskpointView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$isShowBadCommand = false;
		
		$tpModel = new taskpointModel();	
		$ptModel = new pointtypeModel(); 
		$tModel = new taskModel();		
		
		if (isset($get["pointid"]) && isset($get["taskid"]) && isset($get["point"])){
			$pointTypeID = $get["pointid"];
			$taskID = $get["taskid"];
			$point = $get["point"];
			
			$pointTypes = $ptModel->getPointTypesById($pointTypeID);
			$task = $tModel->getSimpleTaskById($taskID);
		
			if (count($pointTypes) > 0 && count($task) > 0)
			{	
				$isTrue = $tpModel->addTaskPoint($pointTypeID, $taskID, $point);
				$status = 0;
				if ($isTrue){
					$this->view->setProperty("status", $isDone);
					$this->view->setProperty("id", $pointTypeID.":".$taskID);
					$this->view->showAddTaskPoint();
				}
				else{				
					$isShowBadCommand = true;
				}
			}
			else{
				$isShowBadCommand = true;
			}			
		}
		else{
			$isShowBadCommand = true;
		}		
		
		if ($isShowBadCommand){
			$this->view->showBadCmd();
		}	
			
	}
}
?>